'use strict';

/* Filters */
//在线状态
app.filter('setNull', function() {
    return function(value) {
    	if(angular.isDefined(value)){
				//return $filter('number')(value,0);
			return value;
    	}else{
    		return "----";
    	}
    }
  });
app.filter('onlineStatus', function() {
	return function(value) {
		if(angular.isDefined(value)){
			if(value == 0){
				return getMessage("common.online") ;
			}
			if(value == 1){
				return getMessage("common.offline");
			}
			if(value == 2){
				return getMessage("common.fault");
			}
		}else{
			return "";
		}
	}
});

/* Filters */
//检测参数
app.filter('detectionItem', function() {
	return function(value) {
		if(angular.isDefined(value)){
			if(value == 0){
				return "airTemperature";
			}
			if(value == 1){
				return "airHumidity";
			}
			if(value == 2){
				return "lightIntensity";
			}
			if(value == 3){
				return "atmosphericPressure";
			}
			if(value == 4){
				return "windSpeed";
			}
			if(value == 5){
				return "windDirection";
			}
			if(value == 6){
				return "rainfall";
			}
			if(value == 7){
				return "pm2_5";
			}
			if(value == 8){
				return "uv";
			}
			if(value == 9){
				return "soilTemperature";
			}
			if(value == 10){
				return "soilMoisture";
			}
			if(value == 11){
				return "co2";
			}
			if(value == 12){
				return "radiation";
			}
			if(value == 13){
				return "surfaceTemperature";
			}
			if(value == 14){
				return "pm10";
			}
			if(value == 15){
				return "noise";
			}
			if(value == 16){
				return "pm1_0";
			}
			if(value == 17){
				return "tsp";
			}
		}else{
			return "";
		}
	}
});
//检测参数回显
app.filter('detection', function() {
	return function(value) {
		if(angular.isDefined(value)){
			if(value == "airTemperature"){
				return 0;
			}
			if(value == "airHumidity"){
				return 1;
			}
			if(value == "lightIntensity"){
				return 2;
			}
			if(value == "atmosphericPressure"){
				return 3;
			}
			if(value == "windSpeed"){
				return 4;
			}
			if(value == "windDirection"){
				return 5;
			}
			if(value == "rainfall"){
				return 6;
			}
			if(value == "pm2_5"){
				return 7;
			}
			if(value == "uv"){
				return 8;
			}
			if(value == "soilTemperature"){
				return 9;
			}
			if(value == "soilMoisture"){
				return 10;
			}
			if(value == "co2"){
				return 11;
			}
			if(value == "radiation"){
				return 12;
			}
			if(value == "surfaceTemperature"){
				return 13;
			}
			if(value == "pm10"){
				return 14;
			}
			if(value == "noise"){
				return 15;
			}
			if(value == "pm1_0"){
				return 16;
			}
			if(value == "tsp"){
				return 17;
			}
		}else{
			return "";
		}
	}
});
//告警状态
app.filter('alarmStatus', function() {
    return function(value) {
    	if(angular.isDefined(value)){
    		if(value == 0){
    			return getMessage('alarm.alarmStatus.noShifted');
    		}
    		if(value == 1){
    			return getMessage('alarm.alarmStatus.shifted');
    		}
    		if(value == 2){
    			return getMessage('alarm.alarmStatus.solved');
    		}
    	}else{
    		return "";
    	}
    }
  });
  //告警状态
app.filter('Lifetime', function() {
    return function(value, showUnit) {
    	if(angular.isDefined(value)){
    		if(value < 0){
    			value = 0;
    		}
    		if(showUnit !== false){
    			value = value + '%';
    		}
    		return value;
    	}else{
    		return "";
    	}
    }
});
//设备类型名称
app.filter('deviceTypeName', function() {
    return function(value) {
    	if(angular.isDefined(value)){
    		var deviceType = '';
			if (value == 1) {
				deviceType = 'device.gateway';
			} else if (value == 24){
				deviceType = 'device.singleLightContrl';
			}else if (value == 25){
				deviceType = 'device.coupleLightContrl';
			}
    		return getMessage(deviceType)
    	}else{
    		return "";
    	}
    }
  });
